package com.webshop.DataDao;

import com.webshop.JavaBean.Picture;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PictureDao {
    QueryRunner queryRunner=new QueryRunner(DataSourceUtils.getDataSource());
  public String findSubPic  (int ID)  {
      String sql="select * from picture where goodsID = ?";
      Object[] objects={ID};
      List<Picture> pictures=new ArrayList<>();
      try {
          pictures =queryRunner.query(sql,new BeanListHandler<>(Picture.class),objects);
      } catch (SQLException e) {
          e.printStackTrace();
      }
      String pic = "";
      for (int i = 0; i < pictures.size(); i++) {
          if(i!=0)
              pic += ",";
            pic += pictures.get(i).getPath();
      }

      return pic;
  }
}
